<template>
  <div class="">
    <!-- 查询和其他操作 -->
    <div class="filter-container" style="margin: 20px;">
      <el-input size="mini" v-model="listQuery.subject" clearable class="filter-item" style="width: 200px;" placeholder="请输入题目名称"/>
      <el-button size="mini" class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button>
      <el-button size="mini" class="filter-item" type="primary" icon="el-icon-edit" @click="handleCreate">新增</el-button>
    </div>

    <!-- 查询结果 -->
    <el-table v-loading="listLoading" style="margin: 20px;" :data="list" size="mini" element-loading-text="正在查询中。。。" highlight-current-row>
      <el-table-column align="center" label="id" prop="categoryName">
        <template slot-scope="scope">
         <div>{{scope.row.chapterQuestionId}}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="章节id" prop="categoryName">
        <template slot-scope="scope">
         <div>{{scope.row.courseSectionId}}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="题目" prop="categoryName">
        <template slot-scope="scope">
         <div>{{scope.row.subject}}</div>
        </template>
      </el-table-column>
    <el-table-column align="center" label="题目类型" prop="categoryName">
        <template slot-scope="scope">
         <div>{{scope.row.subjectType===1?'单选题':'多选题'}}</div>
        </template>
      </el-table-column>

            <el-table-column align="center" label="正确答案" prop="categoryName">
              <template slot-scope="scope">
               <div>{{scope.row.rightKey}}</div>
              </template>
            </el-table-column>

            <el-table-column align="center" label="时间点" prop="categoryName">
              <template slot-scope="scope">
               <div>{{scope.row.timeSecond}}</div>
              </template>
            </el-table-column>
            <el-table-column align="center" label="删除" prop="categoryName">
              <template slot-scope="scope">
               <div>{{scope.row.deleted===1?'已删除':'未删除'}}</div>
              </template>
            </el-table-column>
            <el-table-column align="center" label="创建时间" prop="categoryName">
              <template slot-scope="scope">
               <div>{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</div>
              </template>
            </el-table-column>
            <el-table-column align="center" label="修改时间" prop="categoryName">
              <template slot-scope="scope">
               <div>{{scope.row.updateTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</div>
              </template>
            </el-table-column>
            <el-table-column align="center" label="备注 " prop="categoryName">
              <template slot-scope="scope">
               <div>{{scope.row.remark}}</div>
              </template>
            </el-table-column>

      <!--<el-table-column align="center" label="创建时间" prop="createDate"/>-->
      <el-table-column align="center" label="操作" width="350" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button style="width:20%;"  type="primary" size="mini" @click="handleCourseManage(scope.row)">删除</el-button>
          <el-button style="width:20%;"  type="success" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
          <el-button style="width:20%;"  type="success" size="mini" @click="handleUpdate1(scope.row)">查看选项</el-button>
        </template>
      </el-table-column>
    </el-table>
    <addAnswerDialog ref="addAnswerDialog" @update="handleQuery" />
    <editAnswerDialog ref="editAnswerDialog" @update="handleQuery" />
    <upAnwersDialog ref="upAnwersDialog" @update="handleQuery" />
  </div>
</template>

<script>
  import { parseTime } from '@/utils/formatTime.js'
  import {getAnswerQuery,updateAnswerData,delAnswerData} from '@/api/associatedIndustry.js'
  import addAnswerDialog from './components/addAnswerDialog.vue'
  import editAnswerDialog from './components/editAnswerDialog.vue'
  import upAnwersDialog from './components/upAnwersDialog.vue'
export default {
  components:{
    addAnswerDialog,
    editAnswerDialog,
    upAnwersDialog
  },
  data(){
    return{
      list:[],
      listQuery:{
        currentPage:1,
        pageSize:10
      },
      listLoading:false,
      courseSectionId: undefined,
      chapterQuestionId:undefined
    }
  },
  created(){
    this.courseSectionId = this.$route.query.id
    console.log(this.courseSectionId)
    this.handleQuery()
  },
  methods:{
    handleQuery(){
      getAnswerQuery({courseSectionId: this.courseSectionId, ...this.listQuery}).then(res=>{
        console.log(res)
        this.list=res.data.data.data
        console.log(this.list)
      })
    },
    handleCourseManage(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delAnswerData(row).then(res=>{
          this.handleQuery()
          this.$message.success("删除成功");
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      })
    },
  handleFilter(){
    this.handleQuery()

  },
  //新增
  handleCreate(){
    this.$refs.addAnswerDialog.open(this.courseSectionId)
  },
  //编辑
  handleUpdate(row){
    this.$refs.editAnswerDialog.open(row)
  },
  handleUpdate1(row){
     this.$refs.upAnwersDialog.open(row)
  },
}
}
</script>

<style>
</style>
